﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv=content-type content="text/html; charset=UTF-8">
    <script src="../libs/jquery-1.3.2.min.js" type="text/javascript"></script>
	<style type="text/css">
	.log{
		background-color: red
	}
	.log_done{
		background-color: #EEEEEE
	}
	</style>    
</head>
<body>
<fieldset id='step1'>
<legend>STEP 1</legend>
<button onclick="checkEnvironment()" id='check_env'>Check</button> the Environment: 
<div id='log_environment' class='log'></div>
</fieldset>
<fieldset id='step2' style="display: none">
<legend>STEP 2</legend>Input the connect information for mysql database:<br/><br/>
Mysql Host:<input id='host' value='localhost' ><br/>
Mysql UserName:<input id='unm' value='cm_3' ><br/>
Mysql Password:<input id='pwd' value='cm_3' ><br/>
Mysql Port:<input id='port' value='3306' ><br/>
Mysql Database:<input id='db' value='cm_3' ><br/>
Language:<select id='il8n'><option value='zh-cn'>简体中文</option><!-- option value='en'>Enghlish</option --></select><br/>
<button onclick="sendTheDbInfo()" id="btn_db">Send</button> the DB info to Server
<div id='log_db' class='log'></div>
</fieldset>
<fieldset id='step3' style="display: none">
<legend>STEP 3</legend><button onclick="init()" id="btn_init">Initialize</button> the Database, execute the sqls from /WebContent/file/developer/tables_community-3.xls . This may take 5 minutes or more , please wait for a while.
<div id='log_init' class='log'></div>
</fieldset>
<fieldset id='step4' style="display: none">
<legend>STEP 4</legend>

<button onclick="insert()" id="btn_insert">Insert</button> some basic datas to the database.
<div id='log_insert' class='log'></div>
</fieldset>
<fieldset id='step5' style="display: none">
<legend>STEP 5</legend>
Political Zone Code(<a href='http://www.stats.gov.cn/tjbz/xzqhdm/t20130118_402867249.htm' target='_blank'>What's this?</a>):<input id='zone' /><br/>
<button onclick="simulate()" id="btn_simulate">Simulate</button> a lot of datas to the database. This will take a lot of time. You may skip this step .
<div id='log_simulate' class='log'></div>
</fieldset>
<script type="text/javascript">
/**
 * 检查服务端环境
 * 主要是: config.xml 文件是否可写?安装的时候需要将配置参数写入到 config.xml 中
 * file 文件夹是否可写? 系统的文件上传导入下载,都需要 file 文件夹
 * */
var checkEnvironment = function(){
	$('#check_env').attr("disabled",true);
	$.ajax({
		url: "../jsp/install.jsp?class=install&function=check_environment"
		,dataType: 'json'
        ,type: "POST"		
        ,data: {
			 executor: ""
			,session: ""
        }         
		,success : function(response) {
			$('#log_environment').append(response.msg+"<br/>");
			if(response.status=="1"){
				$('#check_env').attr("disabled",true);
				$('#log_environment').attr("class","log_done");
				$('#step2').css("display","block");
				//$('#step5').css("display","block");
			}else{
				$('#check_env').attr("disabled",false);
			}
		}
		,error : function(response){				
			alert("net error");
			$('#check_env').attr("disabled",false);
		}
	});	
}

/**
 * 配置数据库连接参数
 * 需要修改 config.xml 文件
 * */
var sendTheDbInfo = function(){
	var status = 1;
	
	var host = $('#host').val();	
	if(host==null||host=="")status = 0;
	
	var unm = $('#unm').val();	
	if(unm==null||unm=="")status = 0;
	
	var pwd = $('#pwd').val();	
	//if(pwd==null||pwd=="")status = 0;
	
	var port = $('#port').val();	
	if(port==null||port=="")status = 0;
	
	var db = $('#db').val();	
	if(db==null||db=="")status = 0;
	
	if(status==0){
		alert("Must input everything");
		return;
	}
	
	$('#btn_db').attr("disabled",true);
	$.ajax({
		url: "../jsp/install.jsp?class=install&function=check_db"
		,dataType: 'json'
        ,type: "POST"		
        ,data: {
			 executor: ""
			,session: ""
			
			,unm: unm
			,host: host
			,pwd: pwd
			,db: db
			,port: port
			,il8n: $('#il8n').val()
        }         
		,success : function(response) {
			$('#log_db').append(response.msg+"<br/>");
			if(response.status=="1"){
				$('#btn_db').attr("disabled",true);
				$('#log_db').attr("class","log_done");
				$('#step3').css("display","block");
			}else{
				$('#btn_db').attr("disabled",false);
			}
		}
		,error : function(response){				
			alert("net error");
			$('#btn_db').attr("disabled",false);
		}
	});	
}

/**
 * 初始化数据库表
 * 服务端读取 XLS 文件,抽取 SQL代码并执行
 * SQL中有大量的 数据字典 ,执行会比较费事
 * */
var init = function(){
	$('#btn_init').attr("disabled",true);
	$.ajax({
		url: "../jsp/install.jsp?class=install&function=init"
		,dataType: 'json'
        ,type: "POST"		
        ,data: {
			 executor: ""
			,session: ""
        }         
		,success : function(response) {
			$('#log_init').append(response.msg+"<br/>");
			if(response.status=="1"){
				$('#btn_init').attr("disabled",true);
				$('#log_init').attr("class","log_done");
				$('#step4').css("display","block");
			}else{
				$('#btn_init').attr("disabled",false);
			}
		}
		,error : function(response){				
			alert("net error");
			$('#btn_init').attr("disabled",false);
		}
	});	
}

/**
 * 初始化基础业务数据,包括:
 * 标准体系的数据字典,比如 行政区划编码 行业分类编码 会计分类编码 学科分类编码 高等院校编码  等等
 * 基础业务数据,比如 权限 用户组 用户组-权限 系统用户 等等
 * */
var insert = function(){
	$('#btn_insert').attr("disabled",true);
	$.ajax({
		url: "../jsp/install.jsp?class=install&function=insert"
		,dataType: 'json'
        ,type: "POST"		
        ,data: {
			 executor: ""
			,session: ""

        }         
		,success : function(response) {
			$('#log_insert').append(response.msg+"<br/>");
			if(response.status=="1"){
				$('#btn_insert').attr("disabled",true);
				$('#log_insert').attr("class","log_done");
				$('#step5').css("display","block");
			}else{
				$('#btn_insert').attr("disabled",false);
			}
		}
		,error : function(response){				
			alert("net error");
			$('#btn_insert').attr("disabled",false);
		}
	});	
}

var step = 0;
var urls = [
 "../jsp/install.jsp?class=install&function=basic_group"
,"../jsp/install.jsp?class=install&function=basic_user"
,"../jsp/install.jsp?class=install&function=oa_plan"
,"../jsp/install.jsp?class=install&function=oa_work"

,"../jsp/install.jsp?class=install&function=government_building"
,"../jsp/install.jsp?class=install&function=government_company"
,"../jsp/install.jsp?class=install&function=government_family"
,"../jsp/install.jsp?class=install&function=government_resident"
];


var simulate = function(){
	$('#btn_simulate').attr("disabled",true);
	$.ajax({
		url: urls[step]
		,dataType: 'json'
        ,type: "POST"		
        ,data: {
			 executor: ""
			,session: ""
			,zone: $('#zone').val()
        }         
		,success : function(response) {
			$('#log_simulate').append(response.msg+"<br/>");
			if(response.status=="1"){
				$('#btn_simulate').attr("disabled",true);
				$('#log_simulate').attr("class","log_done");

				if(step==7)return;
				step++;				
				simulate();
			}else{
				$('#btn_simulate').attr("disabled",false);
			}
		}
		,error : function(response){				
			alert("net error");
			$('#btn_simulate').attr("disabled",false);
		}
	});	
}
</script> 
</body>
</html>